#pragma once

#include"Common.cpp"


//单例模式
class PageCache
{
public:
    static PageCache* GetInstance()//获取单例对象
    {
        return &_sInst;
    }
    Span* NewSpan(size_t k);//获取k个页的span
    Span* MapObjectToSpan(void* obj);//将对象映射到span
    void ReleaseSpanToPageCache(Span* span);//将span回收到pagecache中
    std::mutex _pageMtx;//pagecache的互斥锁

private:
    SpanList _spanLists[NPAGES];//PageCache桶的span链表

    //std::unordered_map<PAGE_ID, Span*> _idSpanMap;

    TCMalloc_PageMap2<32 - PAGE_SHIFT> _idSpanMap;

    ObjectPool<Span> _spanPool;//span对象池

    PageCache()//构造函数私有
    {}
    PageCache(const PageCache&) = delete;//禁止拷贝构造

    static PageCache _sInst;//静态单例
};